﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RRStatAndmeteKanneRequest", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RRStatAndmeteKanneRequest))]
    public class RRStatAndmeteKanneRequestSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRRStatAndmeteKanneRequest clazz;
        
        public RRStatAndmeteKanneRequestSerializer(IRRStatAndmeteKanneRequest clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("rahvus");
            if (clazz.Rahvus!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "codRahvused");
                Writer.WriteString(clazz.Rahvus.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Rahvus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("emakeel");
            if (clazz.Emakeel!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "codKeeled");
                Writer.WriteString(clazz.Emakeel.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Emakeel");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("haridus");
            if (clazz.Haridus!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "codHaridused");
                Writer.WriteString(clazz.Haridus.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Haridus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("tegevusala");
            if (clazz.Tegevusala!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "codTegevusalad");
                Writer.WriteString(clazz.Tegevusala.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tegevusala");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("pohjendus");
            if (clazz.Pohjendus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Pohjendus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Pohjendus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kontaktandmed");
            if (clazz.Kontaktandmed!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kontaktandmed))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kontaktandmed");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="rahvus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStatAndmeteKanneRequest>rahvus");
                }
                clazz.Rahvus = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.CodRahvused(Reader.ReadElementString("rahvus"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStatAndmeteKanneRequest>rahvus", Reader.LocalName);
            }
            if (Reader.LocalName=="emakeel") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStatAndmeteKanneRequest>emakeel");
                }
                clazz.Emakeel = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.CodKeeled(Reader.ReadElementString("emakeel"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStatAndmeteKanneRequest>emakeel", Reader.LocalName);
            }
            if (Reader.LocalName=="haridus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStatAndmeteKanneRequest>haridus");
                }
                clazz.Haridus = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.CodHaridused(Reader.ReadElementString("haridus"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStatAndmeteKanneRequest>haridus", Reader.LocalName);
            }
            if (Reader.LocalName=="tegevusala") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStatAndmeteKanneRequest>tegevusala");
                }
                clazz.Tegevusala = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.CodTegevusalad(Reader.ReadElementString("tegevusala"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStatAndmeteKanneRequest>tegevusala", Reader.LocalName);
            }
            if (Reader.LocalName=="pohjendus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStatAndmeteKanneRequest>pohjendus");
                }
                clazz.Pohjendus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("pohjendus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStatAndmeteKanneRequest>pohjendus", Reader.LocalName);
            }
            if (Reader.LocalName=="kontaktandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStatAndmeteKanneRequest>kontaktandmed");
                }
                clazz.Kontaktandmed = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kontaktandmed")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStatAndmeteKanneRequest>kontaktandmed", Reader.LocalName);
            }
        }
    }
}
